//
//  BaseCommonViewController.m
//  JQLive
//
//  Created by Bruce on 2019/11/26.
//  Copyright © 2019 JQLive. All rights reserved.
//

#import "BaseVC.h"
//友盟
//#import <UMAnalytics/MobClick.h>

@interface BaseVC ()

@end

@implementation BaseVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.empty_isLoading = YES;
    self.emptyString = @"暂无数据";
    self.emptyIconName = @"home_empty";//home_empty
    
    _statusBarHeight = (INTERFACE_IS_IPHONEX ? 44 : 20);
    _homeIndicatorHeight = (INTERFACE_IS_IPHONEX ? 34 : 0);
    _topControlHeight = (INTERFACE_IS_IPHONEX ? 88 : 64);
    
//    1. 当UINavigationBar的translucent为YES时（默认值），控件的坐标从屏幕最上方开始计算，即（0，0）
//    2. 当UINavigationBar的translucent为NO时，控件的坐标从导航栏左下方开始计算，即（0，64）或者（0，88）
//    3. 当设置automaticallyAdjustsScrollViewInsets为YES时（默认值），滚动视图的内容会自动避开导航条。
//    4. 当设置automaticallyAdjustsScrollViewInsets为NO时，滚动视图的内容会从顶部开始展示。
//    5. edgesForExtendedLayout：边缘延伸属性，默认为UIRectEdgeAll，控制self.view的显示范围。
//    self.edgesForExtendedLayout = UIRectEdgeNone; //从navigationBar下面开始计算一直到屏幕tabBar上部
//    self.edgesForExtendedLayout = UIRectEdgeAll; //从屏幕边缘计算（默认）
//    self.edgesForExtendedLayout = UIRectEdgeTop; //navigationBar下面开始计算一直到屏幕tabBar上部
//    self.edgesForExtendedLayout = UIRectEdgeBottom;
    
    //从navigationBar下面开始计算一直到屏幕底部
    self.edgesForExtendedLayout = UIRectEdgeAll;
//    滚动式图不需要自适应安全距离，不需要自动判断是否被导航条遮挡
    self.automaticallyAdjustsScrollViewInsets = NO;
    
//    self.navigationController.navigationItem.leftBarButtonItem = [self createBackButton];
    
    // Do any additional setup after loading the view.
}
//#pragma mark 返回按钮
//-(void)popself {
//    [self.navigationController popViewControllerAnimated:YES];
//}
//#pragma mark 创建返回按钮
//-(UIBarButtonItem *)createBackButton {
//    return [[UIBarButtonItem alloc] initWithImage:[UIImage svgImageNamed:@"nav_back" size:CGSizeMake(22, 22)] style:UIBarButtonItemStylePlain target:self action:@selector(popself)];
//}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    if(!self.mobPagename||self.mobPagename.length<=0)
    {
        if (self.title||self.title.length<=0) {
            self.mobPagename = NSStringFromClass(self.class);
        }
        else
        {
            self.mobPagename = self.title;
        }
        
    }
    
//    [MobClick beginLogPageView:self.mobPagename]; //("Pagename"为页面名称，可自定义)

//    [self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
//    
//    [self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
}
- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
//    self.navigationItem.leftBarButtonItem = [self createBackButton];
    
}
#pragma mark 返回按钮
-(void)popself {
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark 创建返回按钮
-(UIBarButtonItem *)createBackButton {
    return [[UIBarButtonItem alloc] initWithImage:[UIImage svgImageNamed:@"nav_back" size:CGSizeMake(22, 22)] style:UIBarButtonItemStylePlain target:self action:@selector(popself)];
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
//    [MobClick endLogPageView:self.mobPagename];
}
// 系统状态栏
- (UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}
/// 点击空白键盘回收
/// @param view 点击的视图
- (BOOL)shouldHideKeyboardWhenTouchInView:(nullable UIView *)view
{
       return YES;
}

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    NSLog(@"%@ dealloc",NSStringFromClass(self.class));
}

- (void)showEmptyViewWithTitle:(NSString *)title
                          desc:(NSString *)desc
{
//    home_empty
//    [self showEmptyViewWithImage:[UIImage imageNamed:@"ic_empty"] text:title detailText:desc buttonTitle:nil buttonAction:nil];
    [self showEmptyViewWithImage:[UIImage svgImageNamed:@"home_empty" size:CGSizeMake(194, 93)] text:title detailText:desc buttonTitle:nil buttonAction:nil];
}

#pragma mark - DZNEmptyDataSetSource and  DZNEmptyDataSetDelegate
- (nullable UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
{
    if (self.empty_isLoading)
    {
        return nil;
    }
    else
    {
//        return [UIImage imageNamed:self.emptyIconName];
        return [UIImage svgImageNamed:@"home_empty" size:CGSizeMake(194, 93)];
    }
}

- (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView
{
    return 0;//-self.topControlHeight;
}

- (NSAttributedString *)descriptionForEmptyDataSet:(UIScrollView *)scrollView
{
    if (self.empty_isLoading)
    {
        return nil;
    }
    else
    {
        NSString *text = self.emptyString;

        NSDictionary* attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:13],
                                     NSForegroundColorAttributeName:kColorWithHex(0x9699A8)};
        return [[NSAttributedString alloc] initWithString:text attributes:attributes];
    }
}

- (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView
{
    return YES;
}

- (void)showAnimation
{
    
}

@end
